<html>
    <head>
        
    </head>
    <body>
        <table id="myGrid"> </table>
    </body>
    <link rel="stylesheet" type="text/css" href="/css/flexigrid/flexigrid.css">
        <script type="text/javascript" src="/js/jquery.js"></script>
        <script type="text/javascript" src="/js/flexigrid.js"></script>
        <script language="javascript" type="text/javascript">

            $("#myGrid").flexigrid({
            url: '/grid/list',
            dataType: 'json',
            colModel : [
            {display: 'ID', name : 'id', width : 50, sortable : true, align: 'center'},
            {display: 'Email', name : 'email', width : 300, sortable : true, align: 'center'},
            {display: 'Name', name : 'login_name', width : 200, sortable : true, align: 'center'},
            {display: 'Status', name : 'status', width : 100, sortable : true, align: 'center'},
            {display: 'Role', name : 'role_name', width : 100, sortable : true, align: 'center'},
            {display: 'Actions', name : 'actions', width : 60, align: 'center'}
            ],
            buttons : [
            {name: 'Add', bclass: 'add', onpress : add},
            {name: 'Delete', bclass: 'delete', onpress : test},
            {separator: true}
            ],
            searchitems : [
            {display: 'Name', name : 'login_name'},
            {display: 'Email', name : 'email'}
            ],
            sortname: "u.login_name",
            sortorder: "asc",
            usepager: true,
            title: 'Users',
            useRp: true,
            rp: 10,
            showTableToggleBtn: true,
            width: 900,
            height: 300,
            singleSelect: true
            });
            function add(){
                window.location.href='admin/adduser/';

            }

            function test1(com, grid){

            $(".trSelected > td:first-child > div:first-child").each( function(index, element){

            alert($(element).html());
            alert(index);
 

            }
            );

            }
            function test(com, grid){

            $(".trSelected > td:first-child > div:first-child").each( function(index, element){
            var user_id=$(element).html();
            if(com == 'Delete'){
	    if(confirm('Are you sure?')){
			$.post('/admin/deleteuser?id='+user_id, {id: user_id}, function(data){
			})
                        $.post('/grid/list', {}, function(data){
			})
                      

                }
            }


            }
            );

            }

        </script>

        </html>




